1.spring配置Freemarker,配置标签
所有目录标签shishuocms_folder_list
ean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">10 UTF-8 UTF-8 zh_CN true,false HH:mm:ss yyyy-MM-dd HH:mm:ss yyyy-MM-dd #.## true
2. 自定义标签类 folderListTag
import static freemarker.template.ObjectWrapper.DEFAULT_WRAPPER;import java.io.IOException;import java.util.List;import java.util.Map;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Service;import com.shishuo.cms.constant.FolderConstant;import com.shishuo.cms.entity.vo.FolderVo;import com.shishuo.cms.service.FolderService;import freemarker.core.Environment;import freemarker.template.TemplateDirectiveBody;import freemarker.template.TemplateDirectiveModel;import freemarker.template.TemplateException;import freemarker.template.TemplateModel;/** * folder标签 * * @author lqq * */@Servicepublic class FolderListTag implements TemplateDirectiveModel { @Autowired private FolderService folderService; public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { // 获取页面的参数 Integer fatherId = Integer.parseInt(params.get("fatherId").toString()); // 获得目录列表 Listlist = folderService.getAllFolderList(fatherId,FolderConstant.Status.display); env.setVariable("tag_folder_list", DEFAULT_WRAPPER.wrap(list)); body.render(env.getOut()); }}
3. 页面展示
@shishuo_cms_folder_list 是 配置中entry key